import axios from "axios";

const github = axios.create({
  timeout:4000,
  baseURL:"http://api.github.com",
  headers: {
    // Authorization:"token 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"
  }
})

//拦截器
github.interceptors.request.use(function (config) {
  return config;
});

github.interceptors.response.use(function (response) {
  let data = response.data;
  //对返回的数据进行整理!!!!
  data.items = data.items.map(item=>({
    username:item.login,
    homepage:item.html_url,
    url:item.avatar_url
  }));


  return data;
}, function (error) {
  return Promise.reject(error);
});

export function getUsersByName(name){
  return github.get("/search/users",{params:{q:name}})
}
